package com.jyh.fanxing;

import java.util.Arrays;

/**
 * @Author JYH
 * @Date 2024/7/31 19:08
 * @Description
 */
public class HomeWork3 {
    public static void main(String[] args) {
    Integer[]arr={1,2,3,4};
        System.out.println(Arrays.toString(arr));
        method(arr,0,1);
        System.out.println(Arrays.toString(arr));
    }

    public static <T> void method(T[] arr, int a, int b) {
        if (a < 0 || a >= arr.length || b < 0 || b >= arr.length) {
            throw new IndexOutOfBoundsException("索引超出数组界限");
        }

        // 交换元素
        T temp = arr[a];
        arr[a] = arr[b];
        arr[b] = temp;
    }

}
